package com.shuai.blog.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/editor.md/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/login_pre.html")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/reg.html")
                .excludePathPatterns("/blog_list.html")
                .excludePathPatterns("/blog_content.html")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/art/getArt")
                .excludePathPatterns("/user/get_id")
                .excludePathPatterns("/art/increment")
                .excludePathPatterns("/art/limit")
                .excludePathPatterns("/for_pass.html")
                .excludePathPatterns("/user/for_pass_name")
                .excludePathPatterns("/user/for_pass_ans")
                .excludePathPatterns("/user/for_pass_update")
                .excludePathPatterns("/user/captcha")
                .excludePathPatterns("/user/ca_loaded")
                .excludePathPatterns("/user/upd_photo");
    }

    @Value("${photoPath}")
    private String photoPath;

    /**
     * 配置映射路径
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("file:" + photoPath);
    }
}
